﻿using System;
using System.Collections.Generic;
using System.Text;

namespace SimpleSfx
{
    class Program
    {

        static int Main(string[] args)
        {
            Console.WriteLine("Dacris Software SimpleSFX Self-Extractor Utility, Version " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
            Console.WriteLine("Copyright (c) Dacris Software Inc. All rights reserved.");
            if (args.Length < 2)
            {
                Console.WriteLine("");
                Console.WriteLine("Creates a self-extracting archive from a ZIP file.");
                Console.WriteLine("Default behavior is to decompress the ZIP file to a temporary directory,");
                Console.WriteLine("then run SETUP.CMD from the root directory of the ZIP file.");
                Console.WriteLine("After SETUP.CMD execution is complete, the temporary directory is removed.");
                Console.WriteLine("");
                Console.WriteLine("SIMPLESFX Zipfile.zip Exefile.exe");
                Console.WriteLine("");
                Console.WriteLine("Embeds 'Zipfile.zip' into 'Exefile.exe'.");
                Console.WriteLine("Note: 'Exefile.exe' must be a copy of Unpacker.exe");
                Console.WriteLine("");
                Console.WriteLine("You may modify resources inside Unpacker.exe if you wish, using ResHacker.");
                Console.WriteLine("Create a template self-extractor (MyUnpacker.exe) to use in your project.");
                Console.WriteLine("");
                Console.WriteLine("The self-extractor is 'Output.exe', generated in the current directory.");
                Console.WriteLine("");
                Console.WriteLine("ERRORLEVELs: 0 => Success, 1 => Error");
                Console.WriteLine("");
                return 1;
            }
            Console.WriteLine("");
            Console.WriteLine("Building Output.exe ...");
            try
            {
                string zipFile = args[0];
                string exeFile = args[1];
                SimpleSfxLib.SFXUtility.BuildSFX(zipFile, exeFile, "Output.exe");
            }
            catch (Exception x)
            {
                Console.WriteLine("ERROR! " + x.ToString());
                System.IO.StreamWriter sw = new System.IO.StreamWriter("SfxError.txt");
                sw.WriteLine("ERROR! " + x.ToString());
                sw.Close();
                return 1;
            }
            return 0;
        }
    }
}
